package com.ddpt.platform.common.enums;

import cn.hutool.core.collection.CollUtil;
import com.ddpt.platform.common.exception.CommonException;
import com.ddpt.platform.common.exception.ErrorEnum;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 商户应用权限枚举
 */
@Getter
public enum MerchantServiceType {

    /**
     * 商户系统
     */
    MERCHANT("MERCHANT","商户系统","RUNNING","商户系统","",""),
    /**
     * 营销活动
     */
    ACTIVITY("ACTIVITY","营销活动管理平台","RUNNING","多类多套热门活动模板，定期迭代更新，运营人员无需懂得编程即可快速配置上线","",""),
    /**
     * 营销画布
     */
    FLOW("FLOW","营销自动化平台","RUNNING","以数据为基础构建实时、精准、敏捷、闭环的图形自动化营销流程，优化企业营销策略，助力实现大规模营销增","",""),
    /**
     * 商城
     */
    MALL("MALL","商城管理平台","RUNNING"," 综合商城管理平台，包括但不限于分期商城、积分商城、权益商城等","",""),
    /**
     * 素材中心
     */
    MATERIAL("MATERIAL","内容管理平台","PREPARING","预置丰富的内容素材库，覆盖新客留存、存量","",""),
    /**
     * 员工营销
     */
    MARKETING("MARKETING","社区经理之家 ","RUNNING"," 一集合厅堂营销、龙虎榜、业绩追踪、客户管理等功能于一体，便捷营销助力增长","",""),

    /**
     * 营销数据驾驶舱
     */
    DATABASE("DATABASE","营销数据驾驶舱","RUNNING","根据用户行为自动化采集系统数据，对营销数据进行多维度统计并支持自助式分析，智能生成多样化图表，为企业提供可视化数据看板","",""),
    /**
     * 智能广告
     */
    AD("AD","综合广告平台","PREPARING","一站式数据智能营销广告精准投放平台","",""),

    /**
     * 厅堂有礼
     */
    TINGTANG("TINGTANG","厅堂有礼 ","RUNNING", " 一集合厅堂营销、龙虎榜、业绩追踪、客户管理等功能于一体，便捷营销助力增长", "","");


    /**
     * 应用code，不可修改且全局唯一
     */
    private String code;

    /**
     * 应用名称，可修改且全局唯一
     */
    private String name;

    /**
     * 应用被选中时图标，可修改
     */
    private String checkedIcon;

    /**
     * 应用图标，可修改
     */
    private String icon;

    /**
     * 应用状态：PREPARING - 开发中,RUNNING - 运行中
     */
    private String status;

    /**
     * 应用描述
     */
    private String description;

    MerchantServiceType(String code,String name,String status,String description,String checkedIcon,String icon) {
        this.code = code;
        this.name = name;
        this.checkedIcon = checkedIcon;
        this.icon = icon;
        this.status = status;
        this.description = description;
    }

    public static MerchantServiceType getInstance(String serviceStr) {
        if(StringUtils.isNotBlank(serviceStr)) {
            for (MerchantServiceType service : values()) {
                if(service.getCode().equals(serviceStr)) {
                    return service;
                }
            }
            throw new CommonException(ErrorEnum.PARAM_ERROR);
        }
        return null;
    }

    public static List<MerchantServiceType> getServiceList(String serviceStr,String separator) {
        if(StringUtils.isBlank(serviceStr)) {
            return null;
        }
        return Arrays.stream(StringUtils.split(serviceStr,separator)).map(ele -> MerchantServiceType.getInstance(ele)).collect(Collectors.toList());
    }

    public static List<MerchantServiceType> getAll(boolean includeMerchant) {
        List<MerchantServiceType> list = CollUtil.newArrayList(values());
        if (!includeMerchant) list.remove(MERCHANT);
        return list;
    }
}
